Repository navigation
[Inflight/Candidate][iOS] Fix for unnecessary arrange passes in CollectionView2 - #39396
Conversation
…iOS CollectionView2 by tracking native bounds changes separately and refining the conditions for inline and final arrangements.
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
|
/azp run maui-pr-uitests , maui-pr-devicetests |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Expert Review — 0 findings
Reviewed commit cd659ce.
MauiBot
left a comment
There was a problem hiding this comment.
Expert Review — 1 findings
See inline comments for details.
The existing test reproduces the regression in candidate CI with 354 arrange passes, exceeding the old limit of 289.8. The proposed limit of 328.65 still rejects this failure while accepting the corrected 327–328 passes reported in this PR. The gate’s 227/231 results did not reproduce the candidate CI scenario. Therefore, the current fix is necessary to resolve the candidate CI failure. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
MauiBot
left a comment
There was a problem hiding this comment.
AI Review Summary
@BagavathiPerumal — new AI review results are available based on commit
cd659ce.
🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix
Gate Result: ❌ FAILED
Platform: IOS · Base: inflight/candidate · Merge base: d099f2e9
🩺 Test does not reproduce the bug — ran the same in both states (PASS without fix, PASS with fix). The repro test is not exercising the issue. Strengthen the test before reviewing the fix.
| Test | Without Fix (expect FAIL) | With Fix (expect PASS) |
|---|---|---|
🖥️ Issue25671 Issue25671 |
❌ PASS — 467s | ✅ PASS — 103s |
🔴 Without fix — 🖥️ Issue25671: PASS ❌ · 467s
(no coded error found; showing last 1200 chars)
please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 10.0.13)
[xUnit.net 00:00:00.05] Discovering: Controls.TestCases.iOS.Tests
[xUnit.net 00:00:00.16] Discovered: Controls.TestCases.iOS.Tests
NUnit Adapter 4.5.0.0: Test execution started
Running selected tests in /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.TestCases.iOS.Tests/Debug/net10.0/Controls.TestCases.iOS.Tests.dll
NUnit3TestExecutor discovered 1 of 1 NUnit test cases using Current Discovery mode, Non-Explicit run
>>>>> 10/16/2026 10:12:00 AM FixtureSetup for Issue25671(iOS)
>>>>> 10/16/2026 10:12:04 AM LayoutPassesShouldNotIncrease Start
>>>>> 10/16/2026 10:12:22 AM LayoutPassesShouldNotIncrease Stop
Measure passes: 271, Arrange passes: 227
Passed LayoutPassesShouldNotIncrease [18 s]
NUnit Adapter 4.5.0.0: Test execution complete
Results File: /Users/cloudtest/vss/_work/1/s/CustomAgentLogsTmp/UITests/TestResults/Issue25671.trx
Test Run Successful.
Total tests: 1
Passed: 1
Total time: 1.3976 Minutes
>>> TRX_RESULT_FILE: /Users/cloudtest/vss/_work/1/s/CustomAgentLogsTmp/UITests/TestResults/Issue25671.trx
🟢 With fix — 🖥️ Issue25671: PASS ✅ · 103s
(no coded error found; showing last 1200 chars)
lease wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 10.0.13)
[xUnit.net 00:00:00.04] Discovering: Controls.TestCases.iOS.Tests
[xUnit.net 00:00:00.14] Discovered: Controls.TestCases.iOS.Tests
NUnit Adapter 4.5.0.0: Test execution started
Running selected tests in /Users/cloudtest/vss/_work/1/s/artifacts/bin/Controls.TestCases.iOS.Tests/Debug/net10.0/Controls.TestCases.iOS.Tests.dll
NUnit3TestExecutor discovered 1 of 1 NUnit test cases using Current Discovery mode, Non-Explicit run
>>>>> 10/16/2026 10:17:18 AM FixtureSetup for Issue25671(iOS)
>>>>> 10/16/2026 10:17:21 AM LayoutPassesShouldNotIncrease Start
>>>>> 10/16/2026 10:17:38 AM LayoutPassesShouldNotIncrease Stop
Measure passes: 317, Arrange passes: 233
Passed LayoutPassesShouldNotIncrease [17 s]
NUnit Adapter 4.5.0.0: Test execution complete
Results File: /Users/cloudtest/vss/_work/1/s/CustomAgentLogsTmp/UITests/TestResults/Issue25671.trx
Test Run Successful.
Total tests: 1
Passed: 1
Total time: 33.4632 Seconds
>>> TRX_RESULT_FILE: /Users/cloudtest/vss/_work/1/s/CustomAgentLogsTmp/UITests/TestResults/Issue25671.trx
⚠️ Failure Details
- ❌ Issue25671 PASSED without fix (should fail) — tests don't catch the bug
📁 Fix files reverted (1 files)
src/Controls/src/Core/Handlers/Items2/iOS/TemplatedCell2.cs
📋 Pre-Flight — Context & Validation
Pre-Flight Context
Scope and PR state
- #39396 contains one commit (
cd659ceb838b8381d54445b290a5da47e549efe5) targetinginflight/candidateat base40a966c82c8aed0cf3cd41f5814b4475a3fcf59b. - GitHub reports it merged on October 16, 2026, into the .NET 10 SR12 candidate line.
- The immutable submitted diff changes two files: one iOS CollectionView2 implementation file and one shared UI-test file.
- This is context gathering only, not an exhaustive or expert review.
Reported problem and lineage
- #39395 reports that the iOS
LayoutPassesShouldNotIncreaseUI test failed in SR12 candidate PR #38782 after the rotation-layout fix from #38771 entered the candidate branch through backport #38815. - The issue contains no standalone reproduction steps, reproduction project, affected iOS version, logs, or workaround. A maintainer comment reports reproduction on iOS from the candidate branch.
- The PR description attributes the increased arrange count to
TemplatedCell2comparing UIKit bounds against the most recent managed arrange size. Preferred-size calculations could update that managed value before UIKit supplied final bounds, obscuring whether native bounds actually changed. - Reported counts are approximately 354 arrange passes for the candidate regression and 327–328 after this change. These numbers are reported evidence, not independently verified here.
- #38815 had addressed a rotation/RTL geometry problem by deferring constraint-change arrangement until
LayoutSubviews; #39396 adjusts that lifecycle again while attempting to retain both rotation correction and synchronous layout for dynamically rebuilt content.
Changed files and mechanism
src/Controls/src/Core/Handlers/Items2/iOS/TemplatedCell2.cs
- Adds
_hasNativeBoundsSizeand_lastNativeBoundsSize, separating consecutive UIKitBounds.Sizeobservations from_lastArrangedSize, which remains the last size passed to the managed virtual view’sArrange. - In
PreferredLayoutAttributesFittingAttributes:- External measure invalidations now request an inline arrange even when outer size is unchanged.
- Constraint changes also request an inline arrange.
- Arrange-induced invalidations with unchanged constraints arrange inline only when the newly calculated size differs from
_lastArrangedSize. - The resulting predicate arranges when an arrange is pending and any of these hold: inline arrangement is requested, no managed arrangement has occurred, or preferred size differs from the last managed arrangement.
- In
LayoutSubviews:- Native bounds changes are detected by comparing current
Bounds.Sizewith the previous native bounds rather than with_lastArrangedSize. - A pending arrange alone no longer unconditionally triggers another final arrange.
- Outside safe-area changes, final arrangement occurs only after native bounds change and when either an arrange remains pending or measured constraints match the applied bounds.
- Native bounds changes are detected by comparing current
- Existing surrounding lifecycle remains relevant:
ArrangeVirtualViewmarks when arrangement is in progress and updates_lastArrangedSize.- Measure invalidation records whether all coalesced invalidations occurred during arrangement.
- Binding and reuse call
ResetArrangeState; that method resets managed-arrange state but does not reset the newly added native-bounds fields. Whether retaining native bounds across reuse/rebinding is intentional requires validation. - Safe-area reconciliation can independently trigger arrangement.
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue25671.cs
- Changes only the iOS
CollectionViewHandler2arrange baseline from276to313; the measure baseline remains373. - Because the assertion permits a 5% margin, the effective arrange limit changes from
289.8to328.65. - The scenario scrolls, regenerates items, scrolls again, then parses displayed measure/arrange counters. No new targeted scenario was added for rotation, native-bound transitions, recycling, or dynamic-content geometry.
- Legacy iOS-handler limits and Android limits are unchanged. The test itself is conditionally compiled only for Android or iOS and uses the new threshold only when the heading identifies
CollectionViewHandler2.
Platform-sensitive paths
- Required validation platform is iOS.
- The implementation is in the UIKit-based CollectionView2 cell lifecycle and affects
PreferredLayoutAttributesFittingAttributes,LayoutSubviews, measure invalidation, managed arrangement, native bounds, and safe-area handling. - Sensitive scenarios include device rotation and RTL layout, vertical versus horizontal collection constraints, dynamically rebuilt templates, recycled or rebound cells, unchanged-size invalidations,
MeasureFirstItemcaching, supplementary headers/footers, and explicit safe-area edges. - This is the Items2/
CollectionViewHandler2path, not the legacy CollectionView handler. - Mac Catalyst applicability should be confirmed because this is shared UIKit-oriented handler code; the PR reports iOS validation only and explicitly leaves Mac unchecked. Android and Windows do not use the changed production file.
Validation requirements and gate evidence
- The supplied Gate result is failed because the tests did not behave as expected; it must not be rerun.
- Available GitHub discussion records that the existing test reportedly passed both without and with the production change in the gate environment, with observed counts of 227 and 231. The author separately reported 354 passes in candidate CI and 327–328 after the fix. The ordering of the gate’s two counts and the reason for the large environment-dependent difference are not established here.
- Later validation therefore needs to establish, on iOS and under the actual candidate configuration:
- that the unpatched candidate reproduces the excessive-arrange condition;
- that the patched version reduces it while the updated threshold still rejects the reported 354-pass behavior;
- that the selected handler and exact UI-test scenario are the same in both runs;
- that rotation uses final UIKit bounds and preserves RTL geometry;
- that dynamic content, rebinding, and recycling receive valid geometry without blank content;
- that unchanged native bounds do not cause redundant final arrangements;
- that genuine native-bound and safe-area changes still receive the required final arrangement.
Remaining uncertainties
- The reason the gate did not discriminate between patched and unpatched behavior is unknown.
- The linked Azure Pipelines build details, attached videos, and raw test artifacts were not established from the available GitHub context.
- It is unknown whether the candidate-only 354-pass result depends on device model, iOS version, orientation, timing, handler selection, or broader candidate contents.
- Direct regression coverage for the native-bounds mechanism is not present in the submitted diff; coverage from other existing tests is unknown.
- Mac Catalyst behavior and the intended lifetime of native-bounds tracking across cell reuse remain unverified.
- The issue remains open in GitHub despite #39396 being reported as merged.
🔬 Code Review — Deep Analysis
Expert Evaluation — PR #39396
Independent Assessment
What this changes: The submitted fix separates the last UIKit Bounds.Size observed by TemplatedCell2 from the last size used for managed arrangement. Preferred sizing can still arrange invalidated content inline, while LayoutSubviews performs a final managed arrangement only for a safe-area change or a genuine native-bounds transition that still requires it. The UI test raises only the iOS CollectionViewHandler2 arrange-pass threshold from 276 to 313.
Inferred motivation: Preferred-size calculation can advance managed arrange state before UIKit applies final cell bounds. Comparing UIKit bounds with that managed size conflates two lifecycles and can either hide a native transition or cause an unnecessary final arrangement.
Platform and Lifecycle Trace
- The production change is confined to the current Items2 handler used by iOS and Mac Catalyst.
- External measure invalidation or a constraint change requests an inline arrangement; an arrange-induced, same-size invalidation does not.
_needsArrangeremains pending after preferred sizing untilLayoutSubviewsreconciles native bounds or establishes convergence.- Rotation/resize can receive both the preferred-size arrangement and a final arrangement using UIKit bounds when native bounds change.
- Safe-area reconciliation remains an independent reason to arrange.
- Rebinding and reuse reset managed arrangement state. Retaining the last native bounds does not by itself skip the required first managed arrangement because
_hasArrangedSizeis reset and bind invalidates measure.
Findings
The single MAUI expert review produced no validated file-line findings. inline-findings.json is the validated empty JSON array ([]). No concrete actionable source defect or unresolved behavioral mechanism met the evidence threshold for a pr-plus-reviewer refinement.
Validation Evidence
- Gate: ❌ FAILED — the supplied Gate did not discriminate the production change. The existing test reportedly passed both without and with the fix in that environment, with counts far below the candidate-branch observations.
- Regression coverage: The submitted diff adjusts an aggregate performance threshold but adds no focused coverage for native-bounds transitions, rotation/RTL geometry, cell reuse, or dynamic-content geometry.
- Consequence: The code mechanism is plausible, but the available evidence does not demonstrate that this submitted change fixes the candidate-only regression while preserving the adjacent layout behaviors. The Gate failure independently blocks approval.
Failure-Mode Probing
- Same-size external invalidation: Preferred sizing arranges inline because the invalidation did not originate from arrangement.
- Same-size arrange-induced invalidation: The size comparison suppresses another inline arrange, and unchanged native bounds allow
LayoutSubviewsto clear the pending work without a redundant cell-level arrange. - Rotation or resize: Changed constraints request inline arrangement, and a subsequent native-bounds change permits final arrangement with UIKit's applied bounds.
- Reuse or rebinding: Reset managed state forces an initial arrangement; a changed native size is still detected against the retained prior bounds.
- Safe-area transition: A changed cell safe-area override remains sufficient to trigger arrangement independently of native-bounds tracking.
External Output Contract
Not applicable.
Verdict: NEEDS_DISCUSSION
Confidence: low
Summary: No concrete code defect survived the expert review, so there is no evidence-backed refinement to implement. However, the failed and non-discriminating Gate leaves the central regression claim unverified; approval is not supported until iOS candidate validation distinguishes patched from unpatched behavior and covers the required layout lifecycle.
🛠️ Try-Fix — Analysis & Comparison
Alternative generation: not requested
Evidence-first mode intentionally omits routine Try-Fix attempts. This is not a failed
attempt, a completed alternative search, or evidence that alternatives have no value.
The expert review may still produce one evidence-backed PR refinement.
🏁 Report — Final Recommendation
⚠️ Final Recommendation: REQUEST CHANGES
Phase Status
| Phase | Status | Notes |
|---|---|---|
| Pre-Flight | ✅ COMPLETE | Trusted evidence-first context consumed |
| Code Review | NEEDS_DISCUSSION (low) | 0 validated inline errors, 0 warnings; validation remains inconclusive |
| Gate | ❌ FAILED | iOS tests did not behave as expected and did not discriminate the fix |
| Try-Fix | NOT REQUESTED | Evidence-first mode intentionally omitted alternative generation |
| Refinement | NOT CREATED | No concrete expert finding met the evidence threshold |
| Report | ✅ COMPLETE |
Code Review and Candidate Comparison
pr is the only real candidate. The single expert pass found no validated file-line defect, and no evidence-backed pr-plus-reviewer patch was implemented. Routine Try-Fix was not requested; this is not a failed or exhausted alternative search.
The submitted change plausibly separates native UIKit bounds tracking from managed arrange state and suppresses redundant final arrangements without removing inline arrangements for invalidated content. Nevertheless, the trusted Gate failed: the available test passed both without and with the production change in the Gate environment, so it did not prove that the fix addresses the candidate-only regression. With no validated alternative candidate, pr is selected solely as the submitted implementation, not as a demonstrated merge-ready fix.
Summary
Request changes because the failed, non-discriminating Gate independently vetoes approval. The submitted mechanism has no blocking expert file-line finding, but the evidence does not establish that it reduces the reported candidate arrange count while preserving rotation, RTL, dynamic-content, reuse, and safe-area behavior.
Root Cause
TemplatedCell2 used the most recent managed arrange size to infer whether UIKit had changed native cell bounds. Preferred sizing can update managed arrange state before UIKit applies final bounds, conflating managed and native layout state and allowing unnecessary final arrangements.
Fix Quality
The production change introduces dedicated native-bounds state and narrows final arrangement to safe-area or genuine native-bounds transitions. It is localized and consistent with the intended lifecycle, but the only submitted test change raises an aggregate arrange threshold and did not reproduce or distinguish the reported regression under Gate. Candidate-configuration iOS evidence is still required before the raw PR can support approval.
📱 UI Tests — CollectionView
Detected UI test categories: CollectionView
✅ Deep UI tests — 438 passed, 0 failed, 5 skipped across 1 category on platform-pool agent (replaces in-process counts above).
🧪 UI Test Execution Results (deep, platform pool)
| Category | Tests | Snapshot diffs |
|---|---|---|
CollectionView |
438/443 (5 skipped) ✓ | — |
📎 Download drop-deep-uitests artifact (TRX + snapshot diffs) |
🧭 Next Steps — review latest findings
No alternative fix was selected for this run. Review the session findings and CI results before merging.
…ctionView2 (#39396) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Root cause The issue occurs because TemplatedCell2 used the most recent managed arrange size to determine whether UIKit had changed the cell’s native bounds. Preferred-size calculations can update this value before UIKit applies its final bounds, making native size changes difficult to detect. PR #38815 allowed any pending arrange to trigger a final arrangement, resulting in redundant arrange passes when the native bounds had not changed and increasing the count to approximately 354. ### Solution description The fix involves tracking UIKit’s native bounds size separately from the last managed arrange size. LayoutSubviewscompares consecutive native bounds and performs a pending final arrangement only when the native bounds have changed. This preserves the rotation correction and required inline arrangements for dynamically rebuilt content while avoiding redundant final arrangements when the native bounds remain unchanged. The corrected implementation reduced the arrange-pass count to approximately 327–328. **Reason for test level changes:** The CollectionView2 arrange count increased because recycled or rebound cells now require an inline managed arrangement after measurement invalidation. This work is necessary to ensure dynamically rebuilt child content receives valid geometry and does not render blank. In addition, a genuine native bounds change, such as device rotation, requires a final arrangement using the bounds supplied by UIKit. These required arrangements raise the valid count above the previous baseline, which was established before the current dynamic-content and rotation layout lifecycle. The baseline is therefore increased from 276 to 313 based on repeated corrected runs producing 327–328 arrangements after the existing 5% margin is applied. This is the smallest baseline that accepts valid behavior while continuing to reject the redundant 354-pass behavior. ### Regression PR PR #38815 Validated the behavior in the following platforms - [x] iOS - [ ] Mac - [ ] Window - [ ] Android ### Issues Fixed Fixes #39395 ### Output |Platform|Before|After| |--|--|--| |iOS| <video src="https://github.com/user-attachments/assets/7ae5fb9f-ed59-4c3a-8b88-02e52d20d104">| <video src="https://github.com/user-attachments/assets/ea367492-c6b5-45d3-ace7-3d8848cdcb6c">|
…e after iOS device rotation #38771 (#39707) The backport PR #38815 caused LayoutPassesShouldNotIncrease to fail (iOS 18.5) in the previous candidate #38782. This PR #39396 fixed that failure, and the candidate was subsequently merged into main. However, the current inflight candidate, #39597, appears to have overwritten that fix with the earlier backport similar changes, possibly during conflict resolution, causing LayoutPassesShouldNotIncrease to fail again. I have now reverted the conflicting changes 4c29bf0 in the candidate to preserve the fix already present in main.
…e after iOS device rotation #38771 (#39707) The backport PR #38815 caused LayoutPassesShouldNotIncrease to fail (iOS 18.5) in the previous candidate #38782. This PR #39396 fixed that failure, and the candidate was subsequently merged into main. However, the current inflight candidate, #39597, appears to have overwritten that fix with the earlier backport similar changes, possibly during conflict resolution, causing LayoutPassesShouldNotIncrease to fail again. I have now reverted the conflicting changes 4c29bf0 in the candidate to preserve the fix already present in main.
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Root cause
The issue occurs because TemplatedCell2 used the most recent managed arrange size to determine whether UIKit had changed the cell’s native bounds. Preferred-size calculations can update this value before UIKit applies its final bounds, making native size changes difficult to detect. PR #38815 allowed any pending arrange to trigger a final arrangement, resulting in redundant arrange passes when the native bounds had not changed and increasing the count to approximately 354.
Solution description
The fix involves tracking UIKit’s native bounds size separately from the last managed arrange size. LayoutSubviewscompares consecutive native bounds and performs a pending final arrangement only when the native bounds have changed. This preserves the rotation correction and required inline arrangements for dynamically rebuilt content while avoiding redundant final arrangements when the native bounds remain unchanged. The corrected implementation reduced the arrange-pass count to approximately 327–328.
Reason for test level changes:
The CollectionView2 arrange count increased because recycled or rebound cells now require an inline managed arrangement after measurement invalidation. This work is necessary to ensure dynamically rebuilt child content receives valid geometry and does not render blank. In addition, a genuine native bounds change, such as device rotation, requires a final arrangement using the bounds supplied by UIKit.
These required arrangements raise the valid count above the previous baseline, which was established before the current dynamic-content and rotation layout lifecycle. The baseline is therefore increased from 276 to 313 based on repeated corrected runs producing 327–328 arrangements after the existing 5% margin is applied. This is the smallest baseline that accepts valid behavior while continuing to reject the redundant 354-pass behavior.
Regression PR
PR #38815
Validated the behavior in the following platforms
Issues Fixed
Fixes #39395
Output
BeforeFix-25671.mov
AfterFix-25671.mov